/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 *
 * $Id: AudioData.hpp,v 1.2 2009-12-01 09:32:21 morsko Exp $
 *
 * \file
 * \brief MaCI - Audio Data encoder/decoder header.
 * \author Matthieu Myrsky <matthieu.myrsky@tkk.fi>
 * \NOTE: Not ready yet!
 */
#ifndef _MACI_INTERFACE_AUDIODATA_HPP_
#define _MACI_INTERFACE_AUDIODATA_HPP_

#include "AudioTypes.hpp"
#include "timestamp.hpp"
#include "MaCIData.hpp"
#include <stdio.h>
#include <map>
#include <vector>

namespace gim {
  namespace binbag{class CBinBag;}
}

namespace MaCI {
  namespace Audio {

    class CAudioContainer;
    /** Audio Data Decoder/Encoder.
     *
     */
    class CAudioData : public CMaCIData
    {
    public:
      /** Constructor.
       *
       */
      CAudioData(void);


      /** Destructor.
       *
       */
      ~CAudioData(void);
      

      /** Copy constructor for AudioData. 
       *
       * The copy constructor duplicates the input object to maximum
       * depth (All containers are duplicated too). After a copy is
       * constructed, no dependencies to original Data element exist.
       *
       * @param[in] aAudioData Reference to CAudioData 
       *            container to copy.
       */
      CAudioData(const CAudioData &aAudioData);

      

      /** Assignment operator for AudioData.
       *
       * The assignment operator duplicates the input object to
       * maximum depth (All containers are duplicated too). After a
       * copy is constructed, no dependencies to original Data element
       * exist.
       *
       * @param[in] aAudioData Reference to CAudioData 
       *            container to copy.
       */
      CAudioData &operator=(const CAudioData &aAudioData);



      ///////////////////////////////////////////////////
      // Derived from 'CMaCIData', see description there.
      bool DecodeFrom(gim::binbag::CBinBag *aBinBag = NULL);
      void Reset();
      void Print(const int level) const;
      ///////////////////////////////////////////////////


      // Setter ocmmands
      /** Set Timestamp element.
       * 
       * \see Common::TTimestamp
       *
       * @param[in] aStamp      Timestamp element to set.
       * @return                'true' if no such element previously
       *                        exists, and a valid binbag::CBinBag backend exists.
       */
      bool SetTimestamp(const Common::TTimestamp &aStamp);


      /** Set Command element.
       *
       * Command elements must be accompanied by related dataelement
       * when required by commandtype. See the command enumerations
       * for a note about required datatype. (For example, 'SetSpeed'
       * command required a 'Speed' datatype after the command.
       * 
       * \see TCommand
       *
       * @param[in] aCmd        Command element to set.
       * @return                'true' if no such element previously
       *                        exists, and a valid binbag::CBinBag backend exists.
       */
      bool SetCommand(const TCommand &aCmd);

      /**
       *
       *
       *
       */
      bool SetAudioInfo(const TAudioInfo &aInfo);

      /** Add a new Audio data element.
       * 
       * This function ADDS a new Audio element to container.
       * Container may contain multiple audios with different types at
       * the same time. Audios may be fetched from the container by
       * calling GetAudio function.
       *
       * @param[in] aAudioData  AudioData container to insert.
       * @return                'true' when adding audio was successfully,
       *                         'false' on failure.
       */
      bool AddAudio( CAudioContainer &aAudioData);

      
      // Getter commands
      /** Get pointer to Common::TTimestamp element (if such exists).
       *
       * \see Common::TTimestamp
       * 
       * @return                Constant pointer to timestamp
       *                        element if such element exists
       *                        in the container. If the element 
       *                        doesn't exist, NULL is returned.
       */
      const Common::TTimestamp *GetTimestamp(void) const;


      /** Get Audio(s) from container.
       *
       * This function fetches audios from the container. With proper
       * parameters, this function is able to fetch all the carried
       * audios in sequence.
       *
       * \note Per default, this function only stores the address of
       * the currently stored data, so if you don't duplicate the data
       * element, you will have to maintain this (CAudioData) object
       * intact as long as the data needs to be used.
       *
       * @param[out] aAudioData  Reference to container which will
       *                         carry the data.
       * @return                 'true', when data was succesfully extracted and
       *                         stored to the provided CAudioContainer container.
       *                         'false' in case of an error; No (more) 
       *                         audios available, or object in invalid state 
       *                         (Must be Valid and ReadOnly)
       */
      bool GetAudio(char **aAudioData,  unsigned int *aSize) const;



    
      /** Get constant pointer to TCommand element (if such exists).
       *
       * \see TCommand
       * 
       * @return                Constant pointer to command
       *                        element if such element exists
       *                        in the container. If the element 
       *                        doesn't exist, NULL is returned.
       */
      const TCommand *GetCommand(void) const;

      /** Get constant pointer to TAudioInfo element (if such exists).
       *
       * \see TAudioInfo
       * 
       * @return                Constant pointer to audioInfo
       *                        element if such element exists
       *                        in the container. If the element 
       *                        doesn't exist, NULL is returned.
       */
      const TAudioInfo *GetAudioInfo(void) const;
    private:
      bool iValid;
      
      const Common::TTimestamp *iTimestampPtr; ///< Pointer to Timestamp
      const TCommand *iCommandPtr; ///< Pointer to command if any.
      const gim::binbag::TBinBlob *iAudioDataPtr;  ///< Pointer to audio data
      const TAudioInfo *iAudioInfo; ///< Pointer to audio info
    };
  }
}


#endif
